package com.mtw.bbs.reply.controller.provide;

import cn.hutool.core.collection.CollectionUtil;
import com.mtw.bbs.common.core.vo.Result;
import com.mtw.bbs.article.pojo.form.ReplyCountForm;
import com.mtw.bbs.article.pojo.vo.ReplyCountVo;
import com.mtw.bbs.reply.service.ReplyProviderService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 *
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("provide/reply")
public class ReplyProvider {

    private final ReplyProviderService replyProviderService;


    @ApiOperation(value = "根据用业务id和实体id获取评论数量", notes = "")
    @PostMapping("/getReplyCount")
    public Result<ReplyCountVo> getCountByBusAndMessageId(@RequestBody ReplyCountForm form){

        if (StringUtils.isBlank(form.getObjectType()) || StringUtils.isBlank(form.getObjectId())){
            return Result.fail("参数为空");
        }
        return Result.success(replyProviderService.getCountByBusAndMessageId(form.getObjectType(), form.getObjectId()));

    }


    @ApiOperation(value = "根据用业务id和实体id集合获取评论数量", notes = "")
    @PostMapping("/getReplyCountList")
    public  Result<List<ReplyCountVo>> getCountByBusAndMessageIds(@RequestBody ReplyCountForm form){

        if (StringUtils.isBlank(form.getObjectType()) || CollectionUtil.isEmpty(form.getObjectIds())){
            return Result.fail("参数为空");
        }
        return Result.success(replyProviderService.getCountByBusAndMessageIds(form.getObjectType(), form.getObjectIds()));
    }

}
